<template>
	<view class="passenger-flow">
		<view class="box_9">
			<con-venues :itemChooselist='itemChooselist' :venuelist='venuelist' @confirm="confirm1"></con-venues>
			<view style="position: fixed;z-index: 999;width: 100%;top: 120rpx;">
				<view class="box_11">
					<view class="image-wrapper_7">
						<u-search @search="search" @custom="search" placeholder="负责人、手机号" :showAction="false" v-model="keyword">
						</u-search>
					</view>
					<view class="label8_list" @click="openFilter">
						<uni-icons type="settings" size="16"></uni-icons>
						<view class="label_88">
							<text>筛选</text>
						</view>
					</view>
				</view>
			</view>
			<!-- 选择会员 -->
			<view class="" style="margin-top: 74rpx;">
				<!-- v-if="plshow" -->
				<scroll-view scroll-y class="listall" v-for="(item,index) in hylist" :key="index" >
					<v-gap />
					<view class="d-flex flex-column listsee">
						<view class="d-flex flex-row justify-space-between">
							<view class="d-flex flex-row align-center">
								<view class="">
									<image style="width: 80rpx;height: 80rpx;border-radius: 10rpx;"
										:src="item.head_img" mode=""></image>
								</view>
								<view class="d-flex flex-column" style="margin-left: 20rpx;">
									<view class="" style="font-size: 26rpx;">
										{{item.qdname||''}} 
									</view>
									<view class="" style="color: #c2c2c2;font-size: 24rpx;margin-top: 10rpx;">
										{{item.qdbianhao||''}}
									</view>
								</view>
							</view>
							<view class="d-flex flex-row align-center">
								<!-- <view class=""
									style="width: 80rpx;height: 50rpx;background: #ccffcc;color: #7cc57e;font-size: 24rpx;text-align: center;border-radius: 25rpx;margin-right: 20rpx;line-height: 50rpx;">
									{{item.sex}}
								</view> -->
								<view class="" @click="onedit(item,index)">
									<image style="width: 30rpx;height: 30rpx;margin-right: 20rpx;" src="https://jiangsudiantuo2022.oss-cn-hangzhou.aliyuncs.com/img/7886aba3ece8aae3b489b1944b48572a4f092c41.png" mode="">
									</image>
								</view>
								<view class="" @click="ondelete(item,index)">
									<image style="width: 30rpx;height: 30rpx;" src="https://jiangsudiantuo2022.oss-cn-hangzhou.aliyuncs.com/img/fe85ef51643a187a6090a929b34e93738e12e365.png" mode="">
									</image>
								</view>
							</view>
						</view>
						<view class="d-flex flex-row" style="font-size: 24rpx;color: #9e9e9e;line-height: 50rpx;">
							<view class="" style="width: 250rpx;">
								姓名：{{item.name||""}} 
							</view>
							<view class="">
								电话：{{item.mobile||""}}
							</view>
						</view>
						<view class="d-flex flex-row" style="font-size: 24rpx;color: #9e9e9e;line-height: 50rpx;">
							<view class="" style="width: 250rpx;">
								待结算：{{item.jiesuan||""}}
							</view>
							<view class="">
								所在地区：{{item.diqu||""}}
							</view>
						</view>
						<view class="d-flex flex-row" style="font-size: 24rpx;color: #9e9e9e;line-height: 50rpx;">
							<view class="" style="width: 250rpx;">
								总计提成：{{item.zjiesuan||""}}
							</view>
							<view class="">
								注册时间：{{item.zctime||""}}
							</view>
						</view>
						<!-- <view class="d-flex flex-row justify-space-between"
							style="font-size: 24rpx;color: #9e9e9e;line-height: 50rpx;">
							<view class=""></view>
							<view class="" @click="handSelects(item)"
								style="width: 200rpx;height: 50rpx;background: linear-gradient(0deg, rgba(214, 53, 53, 0.9), rgba(255, 64, 64, 0.93), rgba(250, 142, 142, 0.93));color: #ffffff;font-size: 24rpx;text-align: center;border-radius: 25rpx;line-height: 50rpx;">
								课包详情
							</view>
						</view> -->
					</view>
				</scroll-view>
				<!-- <scroll-view scroll-y class="listall" v-for="(item,index) in hylist" :key="index" v-if="!plshow"
					@click="handSelect(item)">
					<v-gap style="margin-top: 30rpx;" />
					<view class="d-flex flex-column listsee" :class="{'active1': weekSelect.includes(item.id)}">
						<view class="d-flex flex-row justify-space-between">
							<view class="d-flex flex-row align-center">
								<view class="">
									<image style="width: 80rpx;height: 80rpx;border-radius: 50%;"
										:src="item.head_img" mode=""></image>
								</view>
								<view class="d-flex flex-column" style="margin-left: 20rpx;">
									<view class="" style="font-size: 26rpx;">
										{{item.name}} 
										<text style="margin-left: 20rpx;" v-if="item.sex == 1">男</text>
										<text style="margin-left: 20rpx;" v-if="item.sex == 2">女</text>
									</view>
									<view class="" style="color: #c2c2c2;font-size: 24rpx;">
										{{item.mobile}}
									</view>
								</view>
							</view>
						</view>
						<view class="d-flex flex-row" style="font-size: 24rpx;color: #9e9e9e;line-height: 50rpx;">
							<view class="" style="width: 250rpx;">
								年龄：{{item.age}}岁
							</view>
							<view class="">
								紧急联系人手机号：{{item.custodian_mobile}}
							</view>
						</view>
						<view class="d-flex flex-row" style="font-size: 24rpx;color: #9e9e9e;line-height: 50rpx;">
							<view class="" style="width: 250rpx;">
								生日：{{item.birthday}}
							</view>
							<view class="">
								年级：{{item.grade_name_show}}
							</view>
						</view>
					</view>
				</scroll-view> -->
				<v-gap height="140rpx" color="#EDF5F5" />
			</view>
			<view class="d-flex flex-row justify-space-between justify-center align-center"
				style="position: fixed;bottom: 0;height: 120rpx;background-color: #fff;width: 100%;padding: 0 8%;z-index: 99;">
				<view class="" @click="plbatch" v-if="plshow"
					style="width: 45%;height: 80rpx;background: #ffffff;color: #ff4040;font-size: 24rpx;text-align: center;border-radius: 35rpx;line-height: 80rpx;border:#ff4040 1rpx solid">
					批量操作
				</view>
				<view class="" v-if="!plshow" @click="selectAllWeeks"
					style="width: 45%;height: 80rpx;background: #ffffff;color: #ff4040;font-size: 24rpx;text-align: center;border-radius: 35rpx;line-height: 80rpx;border:#ec6ff404052b 1rpx solid">
					全选
				</view>
				<view class="" @click="addstudent"
					style="width: 45%;height: 80rpx;background: linear-gradient(0deg, rgba(214, 53, 53, 0.9), rgba(255, 64, 64, 0.93), rgba(250, 142, 142, 0.93));color: #ffffff;font-size: 24rpx;text-align: center;border-radius: 35rpx;line-height: 80rpx;">
					添加机构
				</view>
			</view>
			
		</view>
		<u-popup @touchmove.stop :show="showFilterPopup" @close="closehomeInfo" closeOnClickOverlay mode="right">
			<scroll-view class="filter-content" style="height: 100vh;width: 60vw;" scroll-y>
				<view class="filter-item">
					<text class="filter-label">分销商等级</text>
					<view class="item">
						<view class=" week-list flex-wrap">
							<view :class="['week-item', selectId1 === index? 'active' : '']"
								v-for="(item,index) in weekList1" :key="index" @click="timesSelect1(item,index)">
								{{item.venue_name}}
							</view>
						</view>
					</view>
				</view>
				<view class="filter-item">
					<text class="filter-label">来源</text>
					<view class="item">
						<view class=" week-list flex-wrap">
							<view :class="['week-item', selectId6 === index? 'active' : '']"
								v-for="(item,index) in weekList6" :key="index" @click="timesSelect6(item,index)">
								{{item.enum_name}}
							</view>
						</view>
					</view>
				</view>
				<view class="filter-item">
					<text class="filter-label">状态</text>
					<view class="item">
						<view class=" week-list flex-wrap">
							<view class="week-item" :class="['week-item', selectId2 === index? 'active' : '']"
								v-for="(item,index) in weekList2" :key="index" @click="timesSelect2(item,index)">
								{{item.name}}
							</view>
						</view>
					</view>
				</view>
				<!-- <view class="filter-item" style="display: flex;flex-direction: row;justify-content: space-between;">
					<text class="filter-label">七天有课</text>
					<u-checkbox shape='circle' :checked="reg_face"  @change='checkboxChange'>选中</u-checkbox>
				</view> -->
				<!-- 	<view class="filter-item">
					<text class="filter-label">状态</text>
					<view class="item">
						<view class=" week-list flex-wrap">
							<view class="week-item" :class="['week-item', selectId3 === index? 'active' : '']"
								v-for="(item,index) in weekList3" :key="index" @click="timesSelect3(item,index)">
								{{item}}
							</view>
						</view>
					</view>
				</view> -->
				<!-- <view class="filter-item">
					<text class="filter-label">教练</text>
					<view class="item">
						<view class=" week-list flex-wrap">
							<view class="week-item" :class="['week-item', selectId4 === index? 'active' : '']"
								v-for="(item,index) in weekList4" :key="index" @click="timesSelect4(item,index)">
								{{item.coach_name}}
							</view>
						</view>
					</view>
				</view> -->
				<!-- <view class="filter-item">
					<text class="filter-label">课程</text>
					<view class="item">
						<view class=" week-list flex-wrap">
							<view class="week-item" :class="['week-item', selectId5 === index? 'active' : '']"
								v-for="(item,index) in weekList5" :key="index" @click="timesSelect5(item,index)">
								{{item.course_name}}
							</view>
						</view>
					</view>
				</view> -->
			</scroll-view>
		</u-popup>
	</view>
</template>

<script>
	const personal = require("@/api/personal/index.js");
	const venues = require("@/api/venues/venues.js");
	export default {
		data() {
			return {
				filterData: [],
				itemChooselist: {},
				venuelist: [],
				plshow: true,
				weekSelect: [], //选中的
				hylist: [
					{
						qdname:'海西州文化馆',
						qdbianhao:'8460266310',
						head_img: "https://jiangsudiantuo2022.oss-cn-hangzhou.aliyuncs.com/67ca41aebe32b.jpeg",
						name: "扎西旺珠",
						mobile: "15651039802",
						id: 382,
						diqu:'海西蒙古族藏族自治州',
						dengji:'白银',
						yongjin:'20.00%',
						jiesuan:'0.00',
						zctime:'2025-04-30 23:26:15',
						zjiesuan: '0.00',
					}
				],
				isAllSelect: false, //是否全选
				listQuery: { //分页
					pageNo: 1,
					pageSize: 6,
				},
				totalPage: '', //几页
				studentlist:[],
				searchKey:"",
				venue_id:'',
				showFilterPopup:false
			}
		},
		onLoad(options) {
			var data = uni.getStorageSync("wqzdy");
			var items = JSON.parse(data)
			this.venuelist = items
			// this.itemChooselist = this.venuelist[0]
			// 处理itemChooselist的逻辑
			if (this.venuelist.length > 0) {
				this.itemChooselist = this.venuelist[0]
				this.venue_id = this.venuelist[0].id
			} else {
				this.itemChooselist = {}; // 或者设置为其他默认值
			}
		},
		onShow() {
			this.listQuery.pageNo = 1
			// this.studentindex()
		},
		methods: {
			openFilter() {
				this.showFilterPopup = true;
			},
			closehomeInfo() {
				this.showFilterPopup = false;
			},
			async studentindex() {
				let that = this;
				if (this.listQuery.pageNo === 1) that.hylist = [];
				let params = {
					keyword:'15651039802',
					pageSize:this.listQuery.pageSize,
					page:this.listQuery.pageNo,
					venue_id:this.venue_id,
				}
				let res = await venues.studentindex(params)
				if (res.code === 1) {
					that.hylist = that.hylist.concat(res.data.list.data); //将数据拼接在一起
					that.totalPage = res.data.list.last_page
				}
			},
			// 下拉刷新
			onReachBottom() {
				if (this.totalPage <= this.listQuery.pageNo) {
					uni.showToast({
						title: '没有更多了',
						duration: 2000,
						icon: 'none'
					});
					return
				}
				this.listQuery.pageNo += 1;
				this.studentindex()
			},
			search(e){
				this.listQuery.pageNo = 1
				this.searchKey = e
				this.studentindex()
			},
			onedit(item,index){
				uni.navigateTo({
					url: `../channeldetail/index?selectionArr=${encodeURIComponent(JSON.stringify(item))}` + "&status=" + 1 + "&venue_id=" + this.venue_id
				})
			},
			ondelete(item,index){
				let that = this
				uni.showModal({
					title: '提示',
					// 提示文字
					content: '是否删除！',
					// 取消按钮的文字自定义
					cancelText: "取消",
					// 确认按钮的文字自定义
					confirmText: "确定",
					//删除字体的颜色 
					confirmColor: '#000000',
					//取消字体的颜色
					cancelColor: '#999',
					success: function(res) {
						if (res.confirm) {
							let params = {
								id: item.id
							};
							venues.studentdel(params).then(res => {
								if (res.code == 1) {
									uni.$u.toast(res.info);
									setTimeout(() => {
										that.studentindex()
									}, 1000)
								}
							})
						} else {
						}
					}
				})
			},
			// 新增的全选方法
			selectAllWeeks() {
			  if (this.weekSelect.length === this.hylist.length) {
			    // 如果已全选，则清空选中数组
			    this.weekSelect = [];
			  } else {
			    // 如果未全选，则选中所有项目
			    this.weekSelect = this.hylist.map(item => item.id);
			  }
			},
			handSelect(item) {
				let data = item.id;
				// 使用indexOf检查是否已选中，避免重复或遗漏
				const index = this.weekSelect.indexOf(data);
				if (index > -1) {
					// 如果已选中，则移除
					this.weekSelect.splice(index, 1);
				} else {
					// 如果未选中，则添加
					this.weekSelect.push(data);
				}
			},
			handSelects(item) {
				uni.navigateTo({
					url: '../studentdetail/index?student_id=' + item.id
				})
			},
			plbatch() {
				this.plshow = !this.plshow
			},
			confirm(e) {
				uni.navigateTo({
					url: './shaixuan'
				})
				// this.indexArr = e.index;
				// this.valueArr = e.value;

			},
			confirm1(data) {
				this.venue_id = data
			    console.log(data, 'data');
			    // 直接根据接收到的 id 在 venuelist 中查找对应的场馆对象
			    const selectedItem = this.venuelist.find(item => item.id === data);
			    if (selectedItem) {
			        // 将找到的场馆对象赋值给 itemChooselist
			        this.itemChooselist = selectedItem;
			    } else {
			        console.log(`未找到 id 为 ${data} 的场馆对象`);
			    }
			    this.studentindex()
			},
			addstudent() {
				uni.navigateTo({
					url: '../channeldetail/index?venue_id=' + this.venue_id + "&status=" + 2 
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	// @import '../../static/css/member/member_index.scss';
	.passenger-flow {
		width: 100%;
		height: 100vh;
		display: flex;
		flex-direction: column;
		background-color: #EDF5F5;
		padding: 0rpx 0 50rpx 0;
		position: relative;
		
		.filter-content {
			background-color: #ffffff;
			padding: 20rpx 10rpx 20rpx 20rpx;
			border-radius: 32rpx 32rpx 0 0;
		}
		
		.filter-item {
			margin-bottom: 24rpx;
		}
		
		.item {
			// padding: 29rpx 30rpx 30rpx;
			padding: 0 20rpx 20rpx 20rpx;
		
			.atinput {
				// border: #EBECEE 1rpx solid;
				font-size: 24rpx;
				height: 60rpx;
				width: 600rpx;
				padding-left: 20rpx;
			}
		
			.item-title {
				color: rgb(153, 153, 153);
				font-size: 28rpx;
				font-weight: 500;
				margin-bottom: 20rpx;
			}
		
			.value {
				color: rgb(51, 51, 51);
				font-size: 28rpx;
				font-weight: 500;
			}
		
			.time-cell {
				color: rgb(51, 51, 51);
				font-size: 28rpx;
				font-weight: 500;
				justify-content: flex-start;
		
				.time {
					width: 49%;
		
					&:last-of-type {
						margin-left: 20rpx;
					}
				}
			}
		
			.week-list {
				flex-direction: row;
				width: 100%;
				font-size: 24rpx;
				flex-wrap: wrap;
				display: flex;
		
				.week-item {
					padding: 15rpx 0;
					background-color: rgb(243, 243, 243);
					border-radius: 5rpx;
					text-align: center;
					color: rgb(51, 51, 51);
					font-size: 24rpx;
					font-weight: 500;
					border: solid 2rpx transparent;
					box-sizing: border-box;
					padding: 6rpx 12rpx;
					margin-top: 20rpx;
					margin-right: 20rpx;
				}
		
				.active {
					color: rgba(255, 98, 0, 1);
					background-color: rgba(255, 65, 5, 0.1);
					// border: solid 2rpx rgb(99, 93, 247);
					position: relative;
				}
		
				.active1 {
					color: rgba(255, 98, 0, 1);
					background-color: rgba(255, 65, 5, 0.1);
					// border: solid 2rpx rgb(99, 93, 247);
					position: relative;
				}
		
				.active2 {
					color: rgba(255, 98, 0, 1);
					background-color: rgba(255, 65, 5, 0.1);
					// border: solid 2rpx rgb(99, 93, 247);
					position: relative;
				}
		
				.check {
					color: rgb(51, 51, 51);
					font-size: 24rpx;
					position: absolute;
					bottom: 10rpx;
					right: 0;
				}
			}
		}

		.box_9 {
			width: 750rpx;
			height: 100%;
			// margin-bottom: 1rpx;
			display: flex;
			flex-direction: column;

			.tag-list {
				display: flex;
				margin-top: 30rpx;
				padding: 0 20rpx;

				/deep/ view {
					margin-left: 4rpx;
				}
			}

			.box_11 {
				width: 100%;
				height: 130rpx;
				display: flex;
				flex-direction: row;
				background: #ffffff;
				padding: 0 20rpx;

				// .image-wrapper_7 {
				// 	width: 541rpx;
				// 	height: 60rpx;
				// 	flex-direction: row;
				// 	display: flex;
				// 	margin-top: 15rpx;
				// }
				.image-wrapper_7 {
					position: absolute;
					left: 30rpx;
					top: 30rpx;
					width: 600rpx;
					height: 62rpx;
					flex-direction: row;
					display: flex;
				}

				.label_list {
					display: flex;
					flex-direction: column;
					position: absolute;
					justify-content: center;
					/* 相对父元素水平居中 */
					align-items: center;
					/*  子元素相对父元素垂直居中 */
					right: 90rpx;
					width: 80rpx;
					top: 27rpx;

					.label_7 {
						width: 36rpx;
						height: 36rpx;
					}

					.label_77 {
						width: 60rpx;
						height: 36rpx;
						color: #333333;
						font-size: 26rpx;
						text-align: center;
					}
				}

				.label8_list {
					display: flex;
					flex-direction: column;
					position: absolute;
					justify-content: center;
					/* 相对父元素水平居中 */
					align-items: center;
					/*  子元素相对父元素垂直居中 */
					right: 20rpx;
					width: 80rpx;
					top: 27rpx;

					.label_8 {
						width: 36rpx;
						height: 36rpx;
					}

					.label_88 {
						width: 60rpx;
						height: 36rpx;
						color: #333333;
						font-size: 26rpx;
						text-align: center;
					}
				}
			}

			.all_whole {
				width: 100%;
				display: flex;
				flex-direction: column;
				background: #ffffff;

				.all_whole_be {
					display: flex;
					flex-direction: row;
					justify-content: space-around;

					.all_whole_or {
						display: flex;
						flex-direction: column;
						justify-content: center;
						align-items: center;
						width: 20%;
						height: 150rpx;
						border-radius: 20rpx;
					}

					/* 使用类名来设置背景色 */
					.bg-color-all {
						background: linear-gradient(0deg, rgb(173, 201, 246) 0%, rgb(231, 239, 255) 100%);
					}

					.bg-color-reading {
						background: linear-gradient(0deg, #ccffcc 0%, #edffea 100%);
					}

					.bg-color-graduated {
						background: linear-gradient(0deg, #fbdafd 0%, #fdeffd 100%);
					}

					.bg-color-potential {
						background: linear-gradient(0deg, #f9ffcf 0%, #fdffe9 100%);
					}

					.wz-color-all1 {
						font-size: 24rpx;
					}

					.wz-color-all2 {
						color: #3479da;
						font-weight: 600;
						font-size: 26;
					}

					.wz-color-reading2 {
						color: #67ca55;
						font-weight: 600;
						font-size: 26;
					}

					.wz-color-graduated2 {
						color: #a672c6;
						font-weight: 600;
						font-size: 26;
					}

					.wz-color-potential2 {
						color: #b39b64;
						font-weight: 600;
						font-size: 26;
					}
				}

				.all_potent {
					display: flex;
					flex-direction: row;
					justify-content: space-around;
					color: #c2c2c2;
					font-size: 22rpx;
					height: 80rpx;
					width: 100%;
					justify-content: space-between;
					align-items: center;
					padding: 0 20rpx;

					.all_shuju1 {}

					.all_shuju2 {
						display: flex;
						flex-direction: row;
						justify-content: center;
						align-items: center;

						.all_shuju2_img {
							width: 20rpx;
							height: 20rpx;
							margin-right: 10rpx;
						}
					}
				}

				.alls_potent {
					display: flex;
					flex-direction: row;
					justify-content: space-around;
					height: 80rpx;
					width: 100%;
					justify-content: space-between;
					align-items: center;
					padding: 0 20rpx;

					.alls_shuju1 {
						font-size: 28rpx;
					}

					.alls_shuju2 {
						display: flex;
						flex-direction: row;
						justify-content: center;
						align-items: center;

						.alls_shuju2_img {
							width: 20rpx;
							height: 20rpx;
						}
					}
				}
			}

			.listall {
				.listsee {
					background-color: #fff;
					padding: 30rpx;
					border-radius: 10rpx;
					width: 94%;
					margin-left: 3%;
					border: 2rpx #fff solid;
				}

				.active1 {
					border: 2rpx #0000ff solid;
				}
			}

		}
	}
</style>